//
// Created by incar on 2020.07.24.
//

#include <iostream>
#include <opencv2/core/core.hpp>
#include "yolo_v2_class.hpp"

using namespace  std;
std::vector<std::string> objects_names_from_file(std::string const filename) {
    std::ifstream file(filename);
    std::vector<std::string> file_lines;
    if (!file.is_open()) return file_lines;
    for(std::string line; getline(file, line);) file_lines.push_back(line);
    std::cout << "object names loaded \n";
    return file_lines;
}

cv::Rect draw_boxes(cv::Mat mat_img,std::vector<bbox_t> result_vec){
    cv::Rect rect;
    for(auto &i:result_vec){
        if(i.obj_id==0){
            rect = cv::Rect(i.x,i.y,i.w,i.h);
            cv::rectangle(mat_img,rect,cv::Scalar(0,255,255),2);
        }

    }//end for
}

int main(int argc, char *argv[]){



    cout << "当前使用的opencv的版本是:" << CV_VERSION << endl;


    std::string  names_file = "data/coco.names";
    std::string  cfg_file = "cfg/yolov4.cfg";
    std::string  weights_file = "yolov4.weights";
    std::string filename = "/home/incar/data/pic/p2.jpg";//"data/dog.jpg";

    Detector detector(cfg_file, weights_file);

    auto obj_names = objects_names_from_file(names_file);

    cv::Mat mat_img = cv::imread(filename);

    vector<bbox_t> result_vec =detector.detect(mat_img);

    cv::Rect rect=draw_boxes(mat_img,result_vec);
    cv::imshow("yolov4 ",mat_img);
    cv::waitKey(0);







    return 0;

}